home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / prog / graph / maxflow.c < prev    next >
C/C++ Source or Header  |  1994-08-05  |  1KB  |  48 lines

  1. #include <LEDA/graph.h>
  2. #include <LEDA/graph_alg.h>
  3.  
  4.  
  5.  
  6. main(int argc, char** argv)
  7. {
  8.  
  9. graph G;
  10.  
  11. init_random(1234567);
  12.  
  13. cmdline_graph(G,argc,argv);
  14.  
  15. edge_array<int>  cap(G,0);
  16. edge_array<int>  cost(G,0);
  17. edge_array<int>  flow(G,0);
  18. edge_array<double> cap1(G,0);
  19. edge_array<double> cost1(G,0);
  20. edge_array<double> flow1(G,0);
  21.  
  22. edge e;
  23. forall_edges(e,G) cap1[e] = cap[e] = random(1,1000);
  24. forall_edges(e,G) cost1[e] = cost[e] = random(-1000,1000);
  25.  
  26. node s = G.first_node();
  27. node t = G.last_node();
  28.  
  29. float T = used_time();
  30.  
  31. cout << "MAX_FLOW<int>             " << flush;
  32. int f = MAX_FLOW(G,s,t,cap,flow) ;
  33. cout << string("time: %6.2f sec  f = %d",used_time(T),f) << endl;
  34.  
  35. cout << "MAX_FLOW<double>          " << flush;
  36. double f1 = MAX_FLOW(G,s,t,cap1,flow1);
  37. cout << string("time: %6.2f sec  f = %.2f",used_time(T),f1) << endl;
  38.  
  39. cout << "MIN_COST_MAX_FLOW<int>    " << flush;
  40. f = MIN_COST_MAX_FLOW(G,s,t,cap,cost,flow) ;
  41. int c = 0;
  42. forall_edges(e,G) c += cost[e]*flow[e];
  43. cout << string("time: %6.2f sec  f = %d    c = %d",used_time(T),f,c) << endl;
  44.  
  45. return 0;
  46.  
  47. }
  48.